package control.admin;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyFrontController extends CoolServlet {

    @Override
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        try {
            request.setCharacterEncoding("UTF-8");
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(MyFrontController.class.getName()).log(Level.SEVERE,
                    "No se pudo establecer el encoding", ex);
        }
        String form = request.getParameter("form");
        if (form == null || (persistenceMechanism != null
                && persistenceMechanism.equals("none"))) {
            gotoURL(error, request, response);
        } else if (form.equals("errorForm")) {
            gotoNamedResource(error, request, response);
        } else if (form.equals("createClientServlet")) {
            gotoNamedResource(createClientServlet, request, response);
        } else if (form.equals("editProductServlet")) {
            gotoNamedResource(editProductServlet, request, response);
        } else if (form.equals("deleteProductServlet")) {
            gotoNamedResource(deleteProductServlet, request, response);
        } else if (form.equals("readProductServlet")) {
            gotoNamedResource(readProductServlet, request, response);
        } else if (form.equals("createProductServlet")) {
            gotoNamedResource(createProductServlet, request, response);
        } else if (form.equals("loginForm")){
            gotoNamedResource(loginServlet, request, response);
        } else if (form.equals("readDetailsProductServlet")){
            gotoNamedResource(readDetailsProductServlet, request, response);
        }else if (form.equals("addtomycart")){
            gotoNamedResource(addProductToCartServlet, request, response);
        }else {
            gotoURL(error, request, response);
        }
    }
}
